package cn.sdormitory.smartdor.service.impl;

import cn.sdormitory.smartdor.dao.SdAttenceTrackRecordDao;
import cn.sdormitory.smartdor.entity.SdAttenceTrackRecord;
import cn.sdormitory.smartdor.service.SdAttenceTrackRecordService;
import cn.sdormitory.sys.dao.SysUserDao;
import cn.sdormitory.sys.entity.SysUser;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: lx
 * @date: 2023/10/7 13:49
 * @description:
 */
@Service
public class SdAttenceTrackRecordServiceImpl extends ServiceImpl<SdAttenceTrackRecordDao, SdAttenceTrackRecord>
        implements SdAttenceTrackRecordService {

    @Autowired
    SdAttenceTrackRecordDao trackRecordDao;

    @Autowired
    SysUserDao userDao;

    @Override
    public int create(SdAttenceTrackRecord trackRecord) {
        SysUser sysUser = userDao.selectById(trackRecord.getCreateUserId());
        trackRecord.setCreateBy(sysUser.getUsername());
        return this.baseMapper.insert(trackRecord);
    }

    @Override
    public int update(SdAttenceTrackRecord trackRecord) {
        return this.baseMapper.updateById(trackRecord);
    }

    @Override
    public List<SdAttenceTrackRecord> getTrackRecordByDateAndStuId(String contactDate, Long studentId) {
        LambdaQueryWrapper<SdAttenceTrackRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SdAttenceTrackRecord::getContactDate,contactDate)
                .eq(SdAttenceTrackRecord::getStudentId,studentId)
                .orderByAsc(SdAttenceTrackRecord::getCreateTime);
        List<SdAttenceTrackRecord> records = trackRecordDao.selectList(wrapper);
        return records;
    }
}
